/*
 * Copyright:   Copyright (c) 1996-2006 The Agent Factory Working Group.
 *              All rights reserved.
 * Licence:     This file is free software; you can redistribute it and/or
 *              modify it under the terms of the GNU Lesser General Public
 *              License as published by the Free Software Foundation; either
 *              version 2.1, or (at your option) any later version.
 *
 *              This file is distributed in the hope that it will be useful,
 *              but WITHOUT ANY WARRANTY; without even the implied warranty of
 *              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *              GNU Lesser General Public License for more details.
 *
 *              You should have received a copy of the GNU Lesser General Public
 *              License along with Agent Factory; see the file COPYING.  If not,
 *              write to the Free Software Foundation, Inc.,
 *              59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Filename:    Location_MapPerceptor.java
 * Created:     17 February 2008
 */

package org.agentsherpa;

import org.agentsherpa.model.Point;
import com.agentfactory.platform.interfaces.Agent;
import com.agentfactory.platform.interfaces.Perceptor;
import com.agentfactory.platform.logic.FOS;

/**
 *
 * @author  Aidan
 */
public class Location_MapPerceptor extends Perceptor {
    
    public void perceive() {
           try {
            SimulatorService simulator = getSimulator();
            Point location = simulator.getLocation(this.agent);
            adoptBelief("BELIEF(location" + location + ")");
            
           LocationModule_1 locationModule = (LocationModule_1)getModuleByName("location");
           
           Point south =  new Point(location.getX(), location.getY() + 1);
           Point east =  new Point(location.getX() + 1, location.getY());
           
           System.out.println("Location_MapPerceptor: South Point = " + south);
           if (locationModule.isRoad(south)){ 
               System.out.println("Location_MapPerceptor: Decision Made to Move South");
               adoptBelief("BELIEF(moveSouth)");
           } else {
               if (locationModule.isRoad(east)){
                   System.out.println("Location_MapPerceptor: Decision Made to Move East");
                   adoptBelief("BELIEF(moveEast)"); 
                }
           }
            
        }
        catch(PerceptorException e) {
            System.out.println("LocationPerceptor: " + e);
        }
    }
    
    private SimulatorService getSimulator() throws PerceptorException {
        SimulatorService simulator = (SimulatorService) getService("org.agentsherpa.SimulatorService");
        if (simulator == null) {
            throw new PerceptorException("Cannot access SimulatorService");
        }
        return simulator;
    }
}
